

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.caigou51.EventBusClass.UpdateShopCarFragment;
import com.example.administrator.caigou51.EventBusClass.UpdateShopCarRedCount;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.CollectActivity;
import com.example.administrator.caigou51.activity.GBaseActivity;
import com.example.administrator.caigou51.control.DialogGoodsBuy;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.card.CollectGoodsCard;
import com.example.administrator.caigou51.util.ImageUtil;
import com.example.administrator.caigou51.util.ToastUtil;

import de.greenrobot.event.EventBus;


public class CollectGoodsCardView extends CardItemView<CollectGoodsCard> implements View.OnClickListener{
 	private Context mContext;
    private RelativeLayout relativeLayout;
    private ImageView imageViewCheck;
    private ImageView imageViewGoods;
    private ImageView imageViewGoodsTag;
    private TextView textViewName;
    private TextView textViewAddress;
    private LinearLayout linearlayoutLSJ;
    private TextView textViewPriceLSJLeft;
    private TextView textViewRmbLeft;
    private TextView textViewPFJLeft;
    private ImageView imageViewCar;
    private View viewLine;
    private  CollectGoodsCard card;
    private TextView textViewDescTag;

    public CollectGoodsCardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public CollectGoodsCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public CollectGoodsCardView(Context context,
                                    AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    @Override
    public void build(CollectGoodsCard card) {
        // TODO Auto-generated method stub
        super.build(card);
        this.card=card;
        relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        imageViewCheck = (ImageView) findViewById(R.id.imageViewCheck);imageViewCheck.setOnClickListener(this);
        imageViewGoods = (ImageView) findViewById(R.id.imageViewGoods);
        imageViewGoodsTag = (ImageView) findViewById(R.id.imageViewGoodsTag);
        textViewName = (TextView) findViewById(R.id.textViewName);
        textViewAddress = (TextView) findViewById(R.id.textViewAddress);
        linearlayoutLSJ = (LinearLayout) findViewById(R.id.linearlayoutLSJ);
        textViewPriceLSJLeft = (TextView) findViewById(R.id.textViewPriceLSJLeft);
        textViewRmbLeft = (TextView) findViewById(R.id.textViewRmbLeft);
        textViewPFJLeft = (TextView) findViewById(R.id.textViewPFJLeft);
        textViewDescTag=(TextView) findViewById(R.id.textViewDescTag);
        imageViewCar = (ImageView) findViewById(R.id.imageViewCar);imageViewCar.setOnClickListener(this);
        viewLine = (View) findViewById(R.id.viewLine);

        App.displayImageHttpOrFile(card.getCollectBean().getThumb(),imageViewGoods, ImageUtil.OptionsActivity());
        textViewName.setText(card.getCollectBean().getTitle()+"\n"+card.getCollectBean().getProduct_spec());
        textViewAddress.setText(card.getCollectBean().getCorporation());
        textViewPriceLSJLeft.setText(card.getCollectBean().getPrice());
        textViewPFJLeft.setText(card.getCollectBean().getShip_price());

        if (GoodsDetailCardView.Tag_PuTong.equals(card.getCollectBean().getPromotion()))
        {

            imageViewGoodsTag.setVisibility(View.GONE);
            textViewDescTag.setText("批发价：");
            textViewPFJLeft.setText(card.getCollectBean().getShip_price());
        } else if (GoodsDetailCardView.Tag_ZhiJiang.equals(card.getCollectBean().getPromotion()))
        {
            imageViewGoodsTag.setVisibility(View.VISIBLE);
            imageViewGoodsTag.setImageResource(R.drawable.icon_zj);
            textViewDescTag.setText("促销价：");
            textViewPFJLeft.setText(card.getCollectBean().getPromotion_price());
        }else if (GoodsDetailCardView.Tag_ZheKou.equals(card.getCollectBean().getPromotion()))
        {
            imageViewGoodsTag.setVisibility(View.VISIBLE);
            imageViewGoodsTag.setImageResource(R.drawable.icon_zk);
            textViewDescTag.setText("促销价：");
            textViewPFJLeft.setText(card.getCollectBean().getPromotion_price());
        }else
        {
            imageViewGoodsTag.setVisibility(View.GONE);
            textViewDescTag.setText("批发价：");
            textViewPFJLeft.setText(card.getCollectBean().getShip_price());
        }

        if (card.getCollectBean().isCheck())
        {
            imageViewCheck.setImageResource(R.drawable.icon_yes_green);
        }else
        {
            imageViewCheck.setImageResource(R.drawable.icon_circle_grey);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {

            case R.id.imageViewCar:
                DialogGoodsBuy.TaskAddCar("1",null,(GBaseActivity) mContext,card.getCollectBean().getItemid(),true);
                break;
            case R.id.imageViewCheck:
                if (card.getCollectBean().isCheck())
                {
                    imageViewCheck.setImageResource(R.drawable.icon_circle_grey);
                    card.getCollectBean().setCheck(false);

                }else
                {
                    imageViewCheck.setImageResource(R.drawable.icon_yes_green);
                    card.getCollectBean().setCheck(true);

                }
                card.getImageViewAll().setImageResource(R.drawable.icon_circle_grey);
                break;
        }
    }
}
